<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8" />
    <meta
      name="viewport"
      content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no, viewport-fit=cover"
    />
    <meta name="theme-color" content="#000000" />
    <style>
      .mobile {
        display: flex;
        width: 100%;
        align-items: center;
        position: relative;
        flex-direction: column;
        min-height: 100%;
        overflow: scroll;
      }
      .title {
        font-size: 20px;
        padding: 20px 0;
      }
      .button {
        padding: 10px;
        border: 1px solid rgb(0, 178, 237);
        color: rgb(0, 178, 237);
      }
      .tips {
        display: none;
        color: red;
        padding: 5px 0;
      }
      .modal {
        position: fixed;
        width: 100vw;
        height: 100vh;
        background-color: #666;
        top: 0;
        left: 0;
        display: flex;
        align-items: center;
        justify-content: center;
      }
      .modal-body {
        background-color: #fff;
        padding: 10px;
        display: flex;
        flex-direction: column;
        align-items: center;
        width: 80%;
      }
      .modal-body-title {
        font-size: 20px;
        padding: 20px 0;
      }
      .modal-body > p {
        font-size: 14px;
        line-height: 16px;
        color: rgb(128, 128, 128);
        align-self: flex-start;
        margin: 6px;
      }
      .modal-body-button {
        background-color: rgb(40, 192, 68);
        color: rgb(255, 255, 255);
        font-size: 14px;
        margin-top: 6px;
        padding: 10px;
      }
    </style>
    <title>官网</title>
  </head>

  <body>
    <div class="mobile">
      <div class="title" id="title"></div>
      <div class="button" id="button">
        下载应用
      </div>
      <div class="tips">
        点击右上角，在浏览器打开
      </div>
    </div>
    <div class="modal" id="modal">
      <div class="modal-body">
        <div class="modal-body-title">声明</div>
        <p>该内容由用户制作，并托管在本免费社区。</p>
        <p>
          严禁利用本服务发布政治、色情、暴力、宗教等违法违规内容，一旦发现，立即关停账号，并交由公安机关处理
        </p>
        <div class="modal-body-button" id="modalbtn">知道了，进入查看</div>
      </div>
    </div>
  </body>
  <script>
    const config = {
      title: '西柚下载',
      ios:
        'itms-services://?action=download-manifest&url=https://gitee.com/291208005/sound/attach_files/1065243/download/meimei_v1.0.0.plist',
      android:
        'https://gitee.com/291208005/sound/attach_files/1065239/download/meimei_v1.0.0.apk'
    }

    // 判断微信
    function isWeixin () {
      var agent = navigator.userAgent
      return /MicroMessenger/.test(agent)
    }

    function isQQ () {
      const ua = navigator.userAgent.toLowerCase()
      return /QQ\/[0-9]/i.test(ua)
    }

    document.addEventListener('DOMContentLoaded', function () {
      const button = document.querySelector('#button')
      const title = document.querySelector('#title')
      const modal = document.querySelector('#modal')
      const modalbtn = document.querySelector('#modalbtn')
      const tips = document.querySelector('.tips')

      document.title = config.title || '下载'
      title.innerHTML = config.title
      modalbtn.addEventListener('click', function () {
        modal.style.display = 'none'
      })
      button.addEventListener('click', function () {
        if (isWeixin() || isQQ()) {
          tips.style.display = 'block'
        } else {
          if (/(iPhone|iPad|iPod|iOS)/i.test(navigator.userAgent)) {
            window.location.href = config.ios
          } else {
            window.location.href = config.android
          }
        }
      })
    })
  </script>
</html>
